package com.badibadi.mytools;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Set;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.badibadi.infos.Results;
import com.badibadi.uniclubber.R;
import com.google.gson.Gson;
import com.google.zxing.WriterException;
import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Utils {

	public static String path = Environment.getExternalStorageDirectory()
			.getPath() + "/Movies";
	protected static final int PROGRESS_DIALOG = 2;

	public static Handler handler;

	static URL url;
	static InputStream in;
	static String content;
	static double DEF_PI = 3.14159265359; // PI
	static double DEF_2PI = 6.28318530712; // 2*PI
	static double DEF_PI180 = 0.01745329252; // PI/180.0
	static double DEF_R = 6370693.5; // radius of earth

	public static ProgressDialog progress; // 进度条对话框
	public static ProgressDialog progress_noclose; // 进度条对话框

	public static ProgressDialog progress_hen;// 横项进度条
	/**
	 * 创建HttpClient对象
	 */
	public static HttpClient httpClient = new DefaultHttpClient();


	/**
	 * 将json字符串转换成实体类的List
	 * 
	 * @param <T>
	 * @param strJson
	 *            需要解析的json字符串
	 * @param beanClass
	 *            需要解析成的实体类型
	 * @return
	 * @throws JSONException
	 */
	public static <T> List<T> getListByJsonString(String strJson,
			Class<T> beanClass) throws JSONException {

		List<T> list = new ArrayList<T>();

		Gson gson = new Gson();
		JSONArray ja = new JSONArray(strJson);

		for (int i = 0; i < ja.length(); i++) {
			JSONObject jo = ja.getJSONObject(i);
			T t = gson.fromJson(jo.toString(), beanClass);
			list.add(t);
		}

		return list;

	}

	/**
	 * 显示提示消息
	 * 
	 * @param context
	 *            上下文
	 * @param text
	 *            提示内容
	 */
	@SuppressLint("ShowToast")
	public static void showMessage(Context context, String text) {
		if (context != null) {
			Toast.makeText(context, text, 1000).show();
		}
	}

	/**
	 * 进度条对话框
	 * 
	 * @param context
	 */
	public static void showPrgress(Context context) {
		if(progress!=null)
		{
			progress.dismiss();
			progress=null;
		}
		
		if (progress == null) {
			progress = new ProgressDialog(context);
			// progress.setCancelable(false);
			progress.setMessage(context.getString(R.string.loaddatea));
			progress.show();
		}
	}

	public static void showProgress_hen(Context context) {
		if (progress_hen != null) {
			progress_hen.dismiss();
			progress_hen = null;
		}
		try {
			progress_hen = new ProgressDialog(context);
			progress_hen.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
			progress_hen.setMessage(context.getResources().getString(
					R.string.qingshaodeng_));
			progress_hen.setTitle(context.getResources().getString(
					R.string.jiazaizhong_qingshaohou));
			progress_hen.setCancelable(false);
			progress_hen.setProgress(0);
			progress_hen.setMax(100);
			// progress_hen.setCancelable(true);
			progress_hen.show();
		} catch (Exception e) {
		}

	}

	public static void setProgress_henMax(int max) {
		if (progress_hen != null) {
			progress_hen.setMax(max);
		}
	}

	/**
	 * 可以在线程中
	 * 
	 * @param jindu
	 */
	public static void setProgress_hen(int jindu) {
		if (progress_hen != null) {
			progress_hen.setProgress(jindu);
		}

	}

	public static void ExitProgress_hen(Context context) {
		if (progress_hen != null) {
			progress_hen.dismiss();
		}
	}

	/**
	 * 进度条对话框
	 * 
	 * @param context
	 */
	public static void showPrgress_Noclose(Context context) {
		// if (progress != null) {
		progress_noclose = new ProgressDialog(context);
		progress_noclose.setCancelable(false);
		progress_noclose.setMessage(context.getString(R.string.loaddatea));
		progress_noclose.show();
		// }
	}

	/**
	 * 关闭进度条对话框
	 * 
	 * @param context
	 */
	public static void ExitPrgress_Noclose(Context context) {
		if (progress_noclose != null) {
			progress_noclose.dismiss();
		}
	}

	/**
	 * 关闭进度条对话框
	 * 
	 * @param context
	 */
	public static void ExitPrgress(Context context) {
		if (progress != null) {
			progress.dismiss();
			progress=null;
		}
	}



	/**
	 * get
	 * 
	 * @param strUrl
	 * @return
	 */
	public static String getRequest(String urlStr) {

		HttpGet httpGet = new HttpGet(urlStr);
		HttpClient httpClient = new DefaultHttpClient();
		try {

			HttpResponse response = httpClient.execute(httpGet);

			// 显示响应
			content = showResponseResult(response);// 一个私有方法，将响应结果显示出来

		} catch (Exception e) {
			   
		}
		return content;
	}

	/**
	 * 显示响应结果到命令行和TextView
	 * 
	 * @param response
	 */
	public static String showResponseResult(HttpResponse response) {
		String ddd = null;
		if (null == response) {
			return ddd;
		}

		HttpEntity httpEntity = response.getEntity();
		try {
			InputStream inputStream = httpEntity.getContent();
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					inputStream));
			String result = "";
			String line = "";
			while (null != (line = reader.readLine())) {
				result += line;
			}
			ddd = result;

			//    (result);
			// mResult.setText("Response Content from server: " + result);
		} catch (Exception e) {
			   
		}
		return ddd;
	}


	/**
	 * post请求(附加数据类型为Map<String,Object>)
	 * 
	 * @param url
	 * @param params
	 * @return
	 * @throws Exception
	 */
	public static String sendRequest(Map<String, Object> params, String url) {
		String res = null;
		HttpEntity entity = null;
		HttpClient client = new DefaultHttpClient();
		HttpPost post = new HttpPost(url);
		List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>();
		Set<Map.Entry<String, Object>> entrySet = params.entrySet();
		for (Map.Entry<String, Object> entry : entrySet) {
//			   
			BasicNameValuePair bnv = new BasicNameValuePair(entry.getKey(),
					String.valueOf(entry.getValue()));
			list.add(bnv);
		}

		try {
			post.setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8));
//			   
			HttpResponse response = client.execute(post);
//			   
//			   
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				entity = response.getEntity();
				res = EntityUtils.toString(entity);
			}
		} catch (ClientProtocolException e) {
//			   ("错误原因1:" + e.getMessage());
			//    
		} catch (IOException e) {
//			   ("错误原因2:" + e.getMessage());
			//    
		} finally {
			try {
				if (entity != null) {
					entity.consumeContent();
				}
				client.getConnectionManager().shutdown();
			} catch (IOException e) {
				   
			}
		}
		return res;
	}



	/**
	 * 关闭输入输出流
	 * 
	 * @param in
	 * @param out
	 */
	public static void closeStream(InputStream in, OutputStream out) {
		try {
			if (null != in) {
				in.close();
			}
			if (null != out) {
				out.close();
			}
		} catch (IOException e) {
			   
		}
	}


	/**
	 * 显示手机型号
	 * 
	 * @return
	 */
	public static String showBrand() {
		return Build.BRAND;
	}

	/**
	 * 显示手机品牌型号
	 * 
	 * @return
	 */
	public static String showBrandModel() {
		return Build.MODEL;
	}


	/**
	 * 处理json语句
	 * 
	 * @param in
	 * @return
	 */
	public static String JSONTokener(String in) {
		// consume an optional byte order mark (BOM) if it exists
		if (in != null && in.startsWith("\ufeff")) {
			in = in.substring(1);
		}
		return in;
	}

	/**
	 * 获取R.drawable中图片文件并转换为bitmap
	 * 
	 * @param cone
	 *            上下文
	 * @param d
	 *            图片id
	 * @return
	 */
	public static Bitmap BackPicture(Context cone, int d) {
		InputStream is = cone.getResources().openRawResource(d);
		Bitmap mBitmap = BitmapFactory.decodeStream(is);
		return mBitmap;
	}

	/**
	 * 从网络地址中得到当前文件的流
	 * 
	 * @param urll
	 * @return
	 * @throws IOException
	 */
	public static InputStream getImageViewInputStream(String urll)
			throws IOException {
		InputStream inputStream = null;
		URL url = new URL(urll); // 服务器地址
		if (url != null) {
			// 打开连接
			HttpURLConnection httpURLConnection = (HttpURLConnection) url
					.openConnection();
			httpURLConnection.setConnectTimeout(3000);// 设置网络连接超时的时间为3秒
			httpURLConnection.setRequestMethod("GET"); // 设置请求方法为GET
			httpURLConnection.setDoInput(true); // 打开输入流
			int responseCode = httpURLConnection.getResponseCode(); // 获取服务器响应值
			if (responseCode == HttpURLConnection.HTTP_OK) { // 正常连接
				inputStream = httpURLConnection.getInputStream(); // 获取输入流
			}
		}
		return inputStream;
	}

	/**
	 * 从网络地址下载后转换成bitmap
	 * 
	 * @param url
	 * @return
	 */
	public static Bitmap displaypicture(String url) {
		InputStream inputStream;
		try {
			inputStream = getImageViewInputStream(url);
			Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
			return bitmap;
		} catch (IOException e) {
			   
			return null;
		}
	}


	/**
	 * 将时间转化为毫秒(格式:"yyyy-MM-dd")
	 * 
	 * @param d
	 * @return
	 */
	public static long getStringMillis(String d) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			long titi = format.parse(d).getTime();
			return titi;
		} catch (ParseException e) {
			   
			return 0;
		}
	}


	/**
	 * 将时间转化为毫秒(格式:"yyyy-MM-dd HH:mm:ss")
	 * 
	 * @param d
	 * @return
	 */
	public static long getStringMillis_quan(String d, Calendar calendar) {
		if (!panduan_is_cunzai(d, "-")) {
			d = GetSystemCurrentTime1(calendar) + " " + d;
		}
//		   
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			long titi = format.parse(d).getTime();
			return titi;
		} catch (ParseException e) {
			   
			return 0;
		}
	}

	/**
	 * 将时间转化为毫秒(格式:"yyyy.MM.dd")
	 * 
	 * @param d
	 * @return
	 */
	public static long getStringMillis_dian(String d) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
		try {
			long titi = format.parse(d).getTime();
			return titi;
		} catch (ParseException e) {
			   
			return 0;
		}
	}



	/**
	 * 获取当前系统时间 yyyy-mm-dd
	 * 
	 * @param c
	 * @return
	 */

	public static String GetSystemCurrentTime1(Calendar calendar) {
		String year = formatTime(calendar.get(Calendar.YEAR));
		String month = formatTime(calendar.get(Calendar.MONTH) + 1);
		String day = formatTime(calendar.get(Calendar.DAY_OF_MONTH));
		return year + "-" + month + "-" + day;
	}


	/**
	 * 将毫秒（时间戳）转化为日期
	 * 
	 * @param tim时间戳
	 * 
	 * @param data
	 *            要转换的时间格式
	 * 
	 * @return
	 */
	public static String Get_Data(String tim, String data, String add) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(data);
		Calendar calendar = Calendar.getInstance();
		String timee = tim + add;
		long time = Long.valueOf(timee);
		calendar.setTimeInMillis(time);
		return dateFormat.format(calendar.getTime());
	}

	/**
	 *  判断是否超过24小时
	 * @param xian
	 * @param dao
	 * @return
	 * @throws Exception
	 */
	public static String jisuan(String xian, String dao) throws Exception {

		java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		java.util.Date start = sdf.parse(Get_Data(dao, "yyyy-MM-dd HH:mm:ss",
				"000"));
		java.util.Date end = sdf.parse(xian);
		long cha = end.getTime() - start.getTime();
		double result = cha * 1.0 / (1000 * 60 * 60);
		if (result <= 24) {
			return Get_Data(dao, "HH:mm", "000");
		} else {
			return Get_Data(dao, "MM-dd", "000");
		}
	}

	/**
	 * 日期过10判定
	 * 
	 * @param t
	 * @return
	 */
	private static String formatTime(int t) {
		return t >= 10 ? "" + t : "0" + t;// 三元运算符 t>10时取 ""+t
	}

	/**
	 * 解析结果
	 * 
	 * @param context
	 * @param result
	 * @param isShowErrorToast
	 *            是否显示错误提示
	 * @return
	 */
	public static Results checkResult_New(Context context, String result,
			boolean isShowErrorToast) {
		Results reR = new Results();

		if (result == null) {
			return new Results(false, false, "");
		} else {
			boolean ret = false;

			try {
				JSONObject json = new JSONObject(JSONTokener(result));
				ret = json.getBoolean("ret");
				reR.setRet(ret);
				reR.setRetmsg(json.getString("retmsg"));
				reR.setMoredata(json.getBoolean("moredata"));
			} catch (Exception e) {
				   
				return null;
			}
			if (ret == false && isShowErrorToast) {
				Toast.makeText(context, reR.getRetmsg(), Toast.LENGTH_SHORT)
						.show();
			}

			return reR;

		}
	}

	/**
	 * 解析结果
	 * 
	 * @param context
	 * @param result
	 * @return
	 */
	public static Results checkResult_NNN(Context context, String result) {
		// 不显示错误提示
		Results reR = checkResult_New(context, result, false);
		return reR;
	}

	public static String QuChuDian(String d) {
		return d.substring(1, d.length());
	}



	/**
	 * 设置图片的大小
	 * 
	 * @param bm
	 *            图片
	 * @param newWidth
	 *            宽
	 * @param newHeight
	 *            高
	 * @return
	 */
	public static Bitmap scaleImg(Bitmap bm, int newWidth, int newHeight) {
		// 图片源
		// Bitmap bm = BitmapFactory.decodeStream(getResources()
		// .openRawResource(id));
		// 获得图片的宽高
		int width = bm.getWidth();
		int height = bm.getHeight();
		// 设置想要的大小
		int newWidth1 = newWidth;
		int newHeight1 = newHeight;
		// 计算缩放比例
		float scaleWidth = ((float) newWidth1) / width;
		float scaleHeight = ((float) newHeight1) / height;
		// 取得想要缩放的matrix参数
		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		// 得到新的图片
		Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
				true);
		return newbm;
	}



	/**
	 * 返回组件显示数据之前的宽
	 * 
	 * @param v
	 * @return
	 */
	public static int GetAssemblyWidth(final View v) {
		int width = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		int height = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		v.measure(width, height);
		//    ("宽" + v.getMeasuredWidth());
		return v.getMeasuredWidth();

	}

	/**
	 * 返回组件显示数据之前的高
	 * 
	 * @param v
	 * @return
	 */
	public static int GetAssemblyHeight(final View v) {
		int width = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		int height = View.MeasureSpec.makeMeasureSpec(0,
				View.MeasureSpec.UNSPECIFIED);
		v.measure(width, height);
		//    ("高" + v.getMeasuredHeight());
		return v.getMeasuredHeight();
	}



	/**
	 * 根据经纬度获取地图上长距离
	 * 
	 * @param lon1
	 * @param lat1
	 * @param lon2
	 * @param lat2
	 * @return
	 */
	public static String GetLongDistance(double lon1, double lat1, double lon2,
			double lat2) {
		double ew1, ns1, ew2, ns2;
		double distance;
		// 角度转换为弧度
		ew1 = lon1 * DEF_PI180;
		ns1 = lat1 * DEF_PI180;
		ew2 = lon2 * DEF_PI180;
		ns2 = lat2 * DEF_PI180;
		// 求大圆劣弧与球心所夹的角(弧度)
		distance = Math.sin(ns1) * Math.sin(ns2) + Math.cos(ns1)
				* Math.cos(ns2) * Math.cos(ew1 - ew2);
		// 调整到[-1..1]范围内，避免溢出
		if (distance > 1.0)
			distance = 1.0;
		else if (distance < -1.0)
			distance = -1.0;
		// 求大圆劣弧长度
		distance = DEF_R * Math.acos(distance);
		return Backdistance(distance);
	}

	/**
	 * 判断距离是否超出1km
	 * 
	 * @param distance
	 * @return
	 */
	public static String Backdistance(double distance) {
		double dis = 0.0;
		if (distance > 1000) {
			dis = distance / 1000;
			return BackXXXDian(dis, 1) + "km";
		} else {
			return BackXXXDian(dis, 1) + "m";
		}
	}


	/**
	 * 返回小数点后指定位数的数字
	 * 
	 * @param shu
	 *            double型的数字
	 * @param num
	 *            需要保留多少位数
	 * @return
	 */
	public static String BackXXXDian(double shu, int num) {
		BigDecimal bd = new BigDecimal(shu);
		bd = bd.setScale(num, BigDecimal.ROUND_HALF_UP);
		return bd.toString();
	}


	public static boolean Judge_Time(String starttime, String endtime) {
		if (starttime != null && endtime != null) {
			if (Utils.getStringMillis(endtime) >= Utils
					.getStringMillis(starttime)) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}


	/**
	 * 获取用户id
	 * 
	 * @param context
	 * @return
	 */
	public static String getUid(Context context) {
		String uid = new MySharePreferences(context, "user").get("uid", "");// 获取用户id
		return uid;
	}

	/**
	 * 获取用户id
	 * 
	 * @param context
	 * @return
	 */
	public static String getBlack_list_id(Context context) {
		String uid = new MySharePreferences(context, "user").get(
				"black_list_id", "");// 获取用户id
		return uid;
	}

	/**
	 * 获取用户id
	 * 
	 * @param context
	 * @return
	 */
	public static String getPwd(Context context) {
		String Pwd = new MySharePreferences(context, "user").get("Pwd", "");// 获取用户id
		return Pwd;
	}

	/**
	 * 获取用户姓名
	 * 
	 * @param context
	 * @return
	 */
	public static String getu_Name(Context context) {
		String u_Name = new MySharePreferences(context, "user").get("u_Name",
				"");// 获取用户id
		return u_Name;
	}

	/**
	 * 获取用户头像
	 * 
	 * @param context
	 * @return
	 */
	public static String getu_Head(Context context) {
		String u_Head = new MySharePreferences(context, "user").get("u_Head",
				"");// 获取用户id
		return u_Head;
	}

	/**
	 * 获取其他人的id
	 * 
	 * @param context
	 * @return
	 */
	public static String getOtherid(Context context) {
		String uid = new MySharePreferences(context, "Otherid").get("Otherid",
				"");// 获取用户id
		return uid;
	}

	/**
	 * 获取其他人的id
	 * 
	 * @param context
	 * @return
	 */
	public static boolean setOtherid(Context context, String Otherid) {
		MySharePreferences id = new MySharePreferences(context, "Otherid");// 获取用户id

		return id.put("Otherid", Otherid);
	}

	public static String getstring(String key, String value) {
		return "\"" + key + "\":" + "\"" + value + "\"";
	}


	/*
	 * 把十六进制Unicode编码字符串转换为中文字符串
	 */
	public static String unicodeToString(String str) {
		Pattern pattern = Pattern.compile("(\\%u(\\p{XDigit}{4}))");
		Matcher matcher = pattern.matcher(str);
		char ch;
		while (matcher.find()) {
			ch = (char) Integer.parseInt(matcher.group(2), 16);
			str = str.replace(matcher.group(1), ch + "");
		}
		return str;
	}

	public static String Get_System_Time(String data) {
		SimpleDateFormat sDateFormat = new SimpleDateFormat(data);
		String date = sDateFormat.format(new java.util.Date());
		return date;
	}

	public static String getGeRenErWeiMa(String uid) {
		return Constants.ErWeiMa_Space + uid + ".html";
	}

	public static Bitmap getGeRenErWerMa(String uid, int w, int h) {
		// sc2lc89c123dcs25s8c7(俱乐部)
		// sc2lw89c123dcs25s8c7(网站主页)
		String s = Constants.ErWeiMa_Space + uid + ".html";// (个人)
		try {
			return ImageTools.Create2DCode(s, w, h);
		} catch (WriterException e) {
			   
		}
		return null;

	}

	public static String getClubErWeiMa(String cid) {
		return Constants.ErWeiMa_Club + cid + ".html";
	}

	public static Bitmap getClubErWeiMa(String cid, int w, int h) {
		// sc2lc89c123dcs25s8c7(俱乐部)
		// sc2lw89c123dcs25s8c7(网站主页)
		String s = Constants.ErWeiMa_Club + cid + ".html";
		;// (个人)
		try {
			return ImageTools.Create2DCode(s, w, h);
		} catch (WriterException e) {
			   
		}
		return null;

	}

	/**
	 * 临时截取时间的方法（获取年月日的，传入时间格式是1970-01-01 08:33:34）
	 * 
	 * @param sd
	 * @return
	 */
	public static String Back_Data(String sd) {
		if (sd != null) {
			String gd[] = sd.split(" ");
			if (gd.length > 0) {
				try {
					return gd[0].replaceAll("-", "\\.");
				} catch (Exception e) {
					return gd[0];
				}

			} else {
				return sd;
			}
		} else {
			return "";
		}
	}

	// 添加站点的
	public static void AddCity(Context ct, String name, LinearLayout v) {
		LayoutInflater inflater = LayoutInflater.from(ct);
		View view = inflater.inflate(R.layout.addcity, null);
		TextView tv = (TextView) view.findViewById(R.id.city);
		tv.setText("" + name);
		tv.setGravity(Gravity.CENTER);
		v.addView(view);
	}

	/**
	 * 是否需要更新
	 * 
	 * @param context
	 * @return
	 */
	public static boolean isGenXin(Context context) {
		MySharePreferences id = new MySharePreferences(context, "isCanGenXin");// 获取用户id

		String a = id.get("isCanGenXin", "0");
		if (a.equals("0")) {
			return false;
		} else {
			return true;
		}

	}



	/**
	 * 判断一个字符串里的某个字符串是否存在
	 * 
	 * @param content
	 *            在这个字符串里判断
	 * @param sub
	 *            需要判断的字符串
	 * @return
	 */
	public static boolean panduan_is_cunzai(String content, String sub) {
		int a = content.indexOf(sub);
		if (a >= 0) {
			//    ("morning在字符串中的位置:" + a);
//			   
			return true;
		} else {
//			   
			return false;
		}
	}

	/**
	 * 为了解决后台工具出现的图片显示不出来的问题
	 * 
	 * @param con
	 * @return
	 */
	public static String getContent(String con) {
		// String con=activityReadingModel.getIntroduce();
		List<String> child_list = RegexUtils.getImgSrc(con);
		RegexUtils.getImgSrcGroup(con);
		for (int i = 0; i < child_list.size(); i++) {
			if (child_list.get(i).startsWith(Constants.Fei_biaoqing_qianzui4)) {
				con = con.replace(child_list.get(i), Constants.BadiWebImgUrl
						+ "/" + child_list.get(i));
			}
		}

		return con;
	}

	/**
	 * 某一个月第一天
	 * 
	 * @param date
	 * @return
	 */
	public static String getFirstday_Month(Date date, int yue_num) {

		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, yue_num);
		Date theDate = calendar.getTime();

		// 上个月第一天
		GregorianCalendar gcLast = (GregorianCalendar) Calendar.getInstance();
		gcLast.setTime(theDate);
		gcLast.set(Calendar.DAY_OF_MONTH, 1);
		String day_first = df.format(gcLast.getTime());
		StringBuffer str = new StringBuffer().append(day_first);
		day_first = str.toString();

		return day_first;
	}

	/**
	 * 某一个月最后一天
	 * 
	 * @param date
	 * @return
	 */
	public static String getLastday_Month(Date date, int yue_num) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, yue_num);
		calendar.add(Calendar.MONTH, 1); // 加一个月
		calendar.set(Calendar.DATE, 1); // 设置为该月第一天
		calendar.add(Calendar.DATE, -1); // 再减一天即为上个月最后一天
		String day_last = df.format(calendar.getTime());
		StringBuffer endStr = new StringBuffer().append(day_last);
		day_last = endStr.toString();
		return day_last;
	}

	/**
	 * 后台指定的封装格式
	 * 
	 * @param ds
	 * @return
	 */
	public static ArrayList<String> toMailHtmL(String ds) {
		String dg[] = ds.split(",");
		ArrayList<String> list2 = new ArrayList<String>();
		if (dg != null) {
			for (int i = 0; i < dg.length; i++) {
				if (dg[i].startsWith("http")) {
					list2.add("<div style='float:left;overflow:hidden; margin: 20px 0 0 20px; width:320px; height:300px;'> <img width='320' src='"
							+ dg[i] + "' /></div>");
				} else {
					list2.add("<div style='float:left;overflow:hidden; margin: 20px 0 0 20px; width:320px; height:300px;'> <img width='320' src='"
							+ Constants.BadiDownImgUrl + dg[i] + "' /></div>");
				}
			}
		}
		return list2;
	}
}
